package com.xinghai.system.service.impl;

import java.util.List;
import com.xinghai.common.utils.DateUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Service;
import com.xinghai.system.mapper.JsStepMapper;
import com.xinghai.system.domain.JsStep;
import com.xinghai.system.service.IJsStepService;

/**
 * 兑换说明Service业务层处理
 * 
 * @author xinghai
 * @date 2024-08-31
 */
@Service
public class JsStepServiceImpl implements IJsStepService 
{
    @Autowired
    private JsStepMapper jsStepMapper;

    @Autowired
    private SqlSessionFactory sqlSessionFactory;
    /**
     * 查询兑换说明
     * 
     * @param id 兑换说明主键
     * @return 兑换说明
     */
    @Override
    public JsStep getInfo(Long id)
    {
        return jsStepMapper.getInfo(id);
    }

    /**
     * 查询兑换说明列表
     * 
     * @param jsStep 兑换说明
     * @return 兑换说明
     */
    @Override
    public List<JsStep> list(JsStep jsStep)
    {
            jsStep.setDelFlag("0");
        return jsStepMapper.list(jsStep);
    }

    /**
     * 新增兑换说明
     * 
     * @param jsStep 兑换说明
     * @return 结果
     */
    @Override
    public int insert(JsStep jsStep)
    {
        jsStep.setCreateTime(DateUtils.getNowDate());
        return jsStepMapper.insert(jsStep);
    }
    /**
     * 批量新增兑换说明
     *
     * @param jsStepList 兑换说明
     * @return 结果
     */
    @Override
    public int insertBatch(List<JsStep> jsStepList)
    {
        return jsStepMapper.insertBatch(jsStepList);
    }
    /**
     * 修改兑换说明
     * 
     * @param jsStep 兑换说明
     * @return 结果
     */
    @Override
    public int update(JsStep jsStep)
    {
        jsStep.setUpdateTime(DateUtils.getNowDate());
        return jsStepMapper.update(jsStep);
    }

    /**
     * 批量删除兑换说明
     * 
     * @param ids 需要删除的兑换说明主键
     * @return 结果
     */
    @Override
    public int deleteBatch(Long[] ids)
    {
        return jsStepMapper.deleteBatch(ids);
    }

    /**
     * 删除兑换说明信息
     * 
     * @param id 兑换说明主键
     * @return 结果
     */
    @Override
    public int delete(Long id)
    {
        return jsStepMapper.delete(id);
    }

    /**
     * 导入兑换说明信息
     *
     * @param list 兑换说明信息集合
     * @return 结果
     */
    @Override
    @Transactional
    public boolean importData(List<JsStep> list){
        SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
        try {
            JsStepMapper jsStepMapper = sqlSession.getMapper(JsStepMapper.class);
            list.stream().forEach(item -> jsStepMapper.insert(item));
            // 提交数据
            sqlSession.commit();
            sqlSession.rollback();
        } catch (Exception e) {
            sqlSession.rollback();
            return false;
        } finally {
            sqlSession.close();
        }
        return true;
    }
}
